#include "timeshower.h"
#include <QPainter>
#include <QDateTime>
#include <QDebug>

// AsyncLayer(0) 参数0设置图层为同步绘制模式
TimeShower::TimeShower() : AsyncLayer(0) {}

void TimeShower::draw(QPixmap &pixmap)
{
    QPainter painter(&pixmap);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setRenderHint(QPainter::TextAntialiasing, true);

    QString date_str = QDate::currentDate().toString("ddd MMMM d yy");
    QString time_str = QTime::currentTime().toString("hh:mm:ss ap");

    // 绘制圆角框
    QRectF rect(10, 10, 200, 60);
    QColor orange(255, 165, 0);
    painter.setPen(Qt::NoPen);
    painter.setBrush(orange);
    painter.drawRoundedRect(rect, 10, 10);

    // 设置文字属性
    painter.setPen(Qt::white);
    QFont font = painter.font();
    font.setBold(true);
    font.setPointSize(12);
    painter.setFont(font);

    // 绘制光标位置 & 帧率
    painter.drawText(rect.adjusted(10, 10, -10, -10),
                     Qt::AlignLeft | Qt::AlignTop,
                     QString("%1\n%2").arg(date_str, time_str));
}
